package com.tepth.remote.control.delegate.apply.list;

import com.tepth.remote.control.base.bean.ApplyHistoryBean;
import com.tepth.remote.ui.recycler.BaseDataConverter;
import com.tepth.remote.ui.recycler.ItemType;
import com.tepth.remote.ui.recycler.MultipleFields;
import com.tepth.remote.ui.recycler.MultipleItemEntity;

import org.ksoap2.serialization.SoapObject;

import java.util.ArrayList;

/**
 * Description:
 *
 * @author Hequn.Lee
 * @date 2018/11/22
 */
public class ApplyListDataConvert extends BaseDataConverter {
    @Override
    public ArrayList<MultipleItemEntity> convert() {
        final ArrayList<SoapObject> soapArray = getSoapArray();
        final int size = soapArray.size();
        for (int i = 0; i < size; i++) {
            final SoapObject soapObject = soapArray.get(i);
            ApplyHistoryBean bean = new ApplyHistoryBean()
                    .setAutoId(Integer.parseInt(soapObject.getPropertySafelyAsString("Auto_ID")))
                    .setFenceId(Integer.parseInt(soapObject.getPropertySafelyAsString("FK_X_ID")))
                    .setUseFor(Integer.parseInt(soapObject.getPropertySafelyAsString("CS_UseFor")))
                    .setProName(soapObject.getPropertySafelyAsString("ProName"))
                    .setProjectId(Integer.parseInt(soapObject.getPropertySafelyAsString("FK_U_ID")))
                    .setUserName(soapObject.getPropertySafelyAsString("UserName"))
                    .setContext(soapObject.getPropertySafelyAsString("MContext"))
                    .setExceptionType(Integer.parseInt(soapObject.getPropertySafelyAsString("CS_Exception_Type")))
                    .setExName(soapObject.getPropertySafelyAsString("ExName"))
                    .setBeginDate(soapObject.getPropertySafelyAsString("CS_BeginDate"))
                    .setEndDate(soapObject.getPropertySafelyAsString("CS_EndDate"))
                    .setDesc(soapObject.getPropertySafelyAsString("CS_Desc"))
                    .setAuditingId(Integer.parseInt(soapObject.getPropertySafelyAsString("FK_Auditing_U_ID")))
                    .setAuditingName(soapObject.getPropertySafelyAsString("AuditingName"))
                    .setAuditingType(Integer.parseInt(soapObject.getPropertySafelyAsString("FK_Auditing_Type")))
                    .setAuditingTypeName(soapObject.getPropertySafelyAsString("AuditingTypeName"))
                    .setAuditingReason(soapObject.getPropertySafelyAsString("CS_Auditing_Reason"))
                    .setAuditingDate(soapObject.getPropertySafelyAsString("CS_Auditing_Date"))
                    .setCreateDate(soapObject.getPropertySafelyAsString("CreateDate"));
            final MultipleItemEntity entity = MultipleItemEntity.builder()
                    .setItemType(ItemType.APPLY_HISTORY_LIST)
                    .setField(MultipleFields.TITLE, bean.getCreateDate())
                    .setField(MultipleFields.TEXT, bean.getContext())
                    .setField(MultipleFields.NAME, bean.getUserName())
                    .setField(MultipleFields.ID, bean.getAutoId())
                    .setField(MultipleFields.TAG, bean.getAuditingType())
                    .setField(MultipleFields.APPLY_HISTORY_BEAN, bean)
                    .builder();
            ENTITIES.add(entity);
        }
        return ENTITIES;
    }

    private ArrayList<SoapObject> getSoapArray() {
        final ArrayList<SoapObject> soapArray = new ArrayList<>();
        final ArrayList<Object> array = getArrays();
        final int size = array.size();
        for (int i = 0; i < size; i++) {
            soapArray.add((SoapObject) array.get(i));
        }
        return soapArray;
    }
}
